fix(serialization): fix ToolInfo.ParamsOneOf loss during checkpoint deep-copy#1007
Merged
shentongmartin merged 1 commit intoalpha/09from May 6, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha/09 #1007 +/- ##
===========================================
Coverage ? 82.95%
===========================================
Files ? 162
Lines ? 22098
Branches ? 0
===========================================
Hits ? 18332
Misses ? 2532
Partials ? 1234 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6c1d86a to
58b8751
Compare
… InternalSerializer When InternalSerializer marshals a struct value that implements json.Marshaler via pointer receiver (e.g. *ToolInfo), rv.Interface() produces a non-addressable copy. json.Marshal then cannot call the pointer method and falls back to default struct encoding, which skips unexported fields — causing ParamsOneOf data loss after deepCopyState during interrupt/resume. Fix: pass a pointer to json.Marshal by using rv.Addr() when addressable, or copying into reflect.New() otherwise. Change-Id: Ib325f5cbb1f97271f1609d8f29b9669e9ec01d60
58b8751 to
c872aa4
Compare
meguminnnnnnnnn
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ToolInfo.ParamsOneOflost after checkpoint deep-copy during interrupt/resumeInternalSerializerto pass pointer tojson.Marshal, enabling pointer-receiverMarshalJSONKey Insight
InternalSerializer.internalMarshaluses reflection to detect types implementingjson.Marshalerand delegates tojson.Marshal. However, it passes the result ofrv.Interface()— a non-addressable struct value. Go's method dispatch requires an addressable value to call pointer-receiver methods. SinceToolInfo.MarshalJSONis defined on*ToolInfo, the non-addressableToolInfovalue does NOT satisfyjson.Marshaler.json.Marshalfalls back to default struct encoding, which cannot access the unexportedParamsOneOffields — causing silent data loss.The fix ensures we always pass a pointer to
json.Marshal:rv.CanAddr(): userv.Addr().Interface()directlyreflect.New(rt), copy the value, and pass the pointerChanges
internal/serialization/serialization.go— In thecheckMarshalerbranch ofinternalMarshal, ensurejson.Marshalalways receives a pointer so that pointer-receiverMarshalJSONmethods are invoked.Testing
adkinterrupt/cancel tests pass with-race(200+ iterations)composetests pass with-raceMarshalJSONis stored in graph state and checkpointed摘要
ToolInfo.ParamsOneOf在 interrupt/resume checkpoint 深拷贝后丢失InternalSerializer,确保传递指针给json.Marshal,使指针接收者MarshalJSON能被调用核心洞察
InternalSerializer.internalMarshal通过反射检测实现了json.Marshaler的类型,然后委托给json.Marshal。但它传递的是rv.Interface()的结果——一个不可寻址的结构体值。Go 的方法分派要求可寻址的值才能调用指针接收者方法。由于ToolInfo.MarshalJSON定义在*ToolInfo上,不可寻址的ToolInfo值不满足json.Marshaler接口。json.Marshal回退到默认结构体编码,无法访问未导出的ParamsOneOf字段——导致静默数据丢失。修复确保始终传递指针给
json.Marshal:rv.CanAddr():直接使用rv.Addr().Interface()reflect.New(rt),复制值,传递指针变更
internal/serialization/serialization.go— 在internalMarshal的checkMarshaler分支中,确保json.Marshal始终接收指针,以调用指针接收者MarshalJSON方法。